package com.luych.toolbox.common.feign.view.base.service;

import com.luych.toolbox.common.enums.TaskStatus;
import com.luych.toolbox.common.enums.TaskType;
import com.luych.toolbox.common.feign.FeignView;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

@ApiModel("任务信息")
public class TaskView extends FeignView {

    @ApiModelProperty("名称")
    private String name;
    @ApiModelProperty("类型")
    private TaskType type;
    @ApiModelProperty("状态")
    private TaskStatus status;
    @ApiModelProperty("关联资源id")
    private String resourceId;
    @ApiModelProperty("描述")
    private String description;
    @ApiModelProperty("输入")
    private String stdin;
    @ApiModelProperty("输出")
    private String stdout;
    @ApiModelProperty("开始时间")
    private Date startDate;
    @ApiModelProperty("结束时间")
    private Date finishDate;
    @ApiModelProperty("耗时(毫秒)")
    private Long cost;
    @ApiModelProperty("预估(毫秒)")
    private Long evaluate;
    @ApiModelProperty("任务日志")
    private List<TaskLogView> logs;
    @ApiModelProperty("责任人")
    private UserView owner;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public TaskType getType() {
        return type;
    }

    public void setType(TaskType type) {
        this.type = type;
    }

    public TaskStatus getStatus() {
        return status;
    }

    public String getStatusValue() {
        return status == null ? null : status.getValue();
    }

    public void setStatus(TaskStatus status) {
        this.status = status;
    }

    public String getResourceId() {
        return resourceId;
    }

    public void setResourceId(String resourceId) {
        this.resourceId = resourceId;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getStdin() {
        return stdin;
    }

    public void setStdin(String stdin) {
        this.stdin = stdin;
    }

    public String getStdout() {
        return stdout;
    }

    public String getStdlog() {
        if (logs != null && !logs.isEmpty()) {
            return logs.stream().map(TaskLogView::getOut).collect(Collectors.joining("\r\n"));
        } else if (stdout != null && !stdout.isEmpty()) {
            return stdout;
        } else {
            return null;
        }
    }

    public void setStdout(String stdout) {
        this.stdout = stdout;
    }

    public Date getStartDate() {
        return startDate;
    }

    public void setStartDate(Date startDate) {
        this.startDate = startDate;
    }

    public Date getFinishDate() {
        return finishDate;
    }

    public void setFinishDate(Date finishDate) {
        this.finishDate = finishDate;
    }

    public Long getCost() {
        return cost;
    }

    public void setCost(Long cost) {
        this.cost = cost;
    }

    public Long getEvaluate() {
        return evaluate;
    }

    public void setEvaluate(Long evaluate) {
        this.evaluate = evaluate;
    }

    public List<TaskLogView> getLogs() {
        return logs;
    }

    public void setLogs(List<TaskLogView> logs) {
        this.logs = logs;
    }

    public UserView getOwner() {
        return owner;
    }

    public void setOwner(UserView owner) {
        this.owner = owner;
    }

    public String getOwnerId() {
        return owner == null ? null : owner.getId();
    }
}
